package com.okaysoft.ofb.account

class Department {

    String name
    Long parentId
    String description
    Integer orderNumber = 0

    static constraints = {
        parentId(nullable: true)
        description(nullable: true)
    }

    List<Department> children() {
        Department.findAllByParentId(this.id,[sort:'orderNumber',order:'asc'])
    }
    
    String getParentName() {
        Department.get(parentId)?.name
    }
}
